<%--
 *  File:    ActivityManageProdSummary.jsp
 *  @Author: Hilldao
 *  Date:    2010/07/31
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%
  //init param
  Category cat = Category.getInstance("jsp.DistributortenderProd");
   
  String strModuleName = "DMS";
  String strTableName = "v_activitymanageprod";
  Integer sourceorgid = new Integer(-1);
  String contextPath = request.getContextPath();
  String isView = request.getParameter("isview");
  if(isView == null && session.getAttribute("isview") != null){
  	isView = session.getAttribute("isview").toString();
  }
%>



<%
  //get userinfo
  HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");

%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<head>
<title>ActivityManageProdSummary</title>
<PageFlow:CheckPageFlow pageName="p_activitymanageprod"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<iframe name="reloadHandler" style="display:none" ></iframe>
<%

  //OvalCustomTable table = new OvalCustomTable(strLanguageCode);
  //OvalCustomColumn column = new OvalCustomColumn(strLanguageCode);


  Vector visitprocessprodinfo = (Vector)pageContext.getAttribute("visitprocessprodinfo");
  if(visitprocessprodinfo == null)
  {
    visitprocessprodinfo = new Vector();
  }

    HashMap orgInfo = (HashMap)pageContext.getAttribute("orginfo");
	if (orgInfo == null) orgInfo = new HashMap();

    boolean ispharmacy = false;

    Integer globalPCCode =  (Integer)orgInfo.get("globalpccode");

	
	Integer zmylcustomtype =  (Integer)orgInfo.get("zmylcustomtype");


	if(globalPCCode == null) globalPCCode = new Integer("-1");
    if(zmylcustomtype == null) globalPCCode = new Integer("-1");
	/*if(new Integer(114).equals(globalPCCode)&&new Integer(10).equals(zmylcustomtype)){
		 ispharmacy=true;
	}*/
	
	Integer activitymanageid =  (Integer)pageContext.getAttribute("activitymanageid");
	

%>
<script>

function page_add()
{

  //if(!checkALLElems(document.getElementById("newdetail"))) return;
   <%if(ispharmacy){%>
  if(isEmpty(document.resoninfoform.employeeid.value)&&isEmpty(document.resoninfoform.hospitalid.value))
   { alert("<%= message.getMessageDesc("P_Please_Select_Employee_Or_Hospital") %>");
      return;
    }
  <%}%>
    if(!checkForm(document.resoninfoform))return;
    document.resoninfoform.actionname.value = "add";
	isRunning = true;
    document.resoninfoform.target = "_self";
	document.resoninfoform.submit();
}
function page_save()
{
    emptyToNull(document.resoninfoform);
    document.resoninfoform.prodids.command="";
    if(!checkForm(document.resoninfoform))return;
    document.resoninfoform.actionname.value = "save";
	isRunning = true;
    document.resoninfoform.target = "_self";
	document.resoninfoform.submit();
}
function page_delete() {

  if (checkedNumber(document.resoninfoform.deleteids) == 0) {
     alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
  }

  document.resoninfoform.actionname.value = "delete";
	isRunning = true;
    document.resoninfoform.target = "_self";
	document.resoninfoform.submit();
}
function checkedNumber(ids) {
  if(ids == null)
    return 0;
  if(ids.length == null) {
    if(ids.checked)
      return 1;
    else
      return 0;
  }
  var count = 0;
  for(var i = 0; i < ids.length; i ++) {
    if(ids[i].checked)
      count ++;
  }
  return count;
}

function page_summary(actionvalue,orderbyname)
{
  
  var editform = summaryPrepare(resoninfoform,actionvalue,orderbyname);
  editform.action = "ActivityManageProdSummary.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}
function parentemppop()
{
   if(isEmpty(document.resoninfoform.zmylprodgroupid.value))
   { alert("<%= message.getMessageDesc("P_Please_Frist_Select_Prodgroup") %>");
      return;
    }
  window.open("EmployeeSelect.jsp?<%= OvalTools.randomURL() %>&employeetype="+document.resoninfoform.employeetype.value+"&selectoption=owner&languagecode=<%= strLanguageCode %>&employeeid="+document.resoninfoform.employeeid.value, "newwindow", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
function parentemppop1()
{

  window.open("ProductbrandPopWindow.jsp?<%= OvalTools.randomURL() %>&zmylorgid="+document.resoninfoform.orgid.value+"&selectoption=owner&languagecode=<%= strLanguageCode %>&employeeid="+document.resoninfoform.employeeid.value +"&globalpccode="+document.resoninfoform.globalpccode.value, "newwindow", "height=400, width=600,top=120,left=120,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=yes");
}
function page_setEmployee(id,name,code)
{ 
  document.resoninfoform.employeeid.value = id;
  document.resoninfoform.employeecode.value = name;
  document.resoninfoform.employeename.value = code;
  <%if(ispharmacy){%>
  resoninfoform.hospitalid.value = "";
  resoninfoform.hospitalname.value = "";
  <%}%>
}
function set_orgNameByPopWindow(id,code,name){
	document.resoninfoform.prodgroupcode.value=code;
	document.resoninfoform.prodgroupname.value=name;
	document.resoninfoform.zmylprodgroupid.value=id;
    reloadprodgroup();
}

/*function poporg()
{
  window.open("../ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>&orgglobalpccode=113&selectoption=switchglobalpccode&orgid="+resoninfoform.orgid.value+"&languagecode=<%= strLanguageCode %>", "newwindow", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}*/
function page_setOrg(id,name,code)
{
  resoninfoform.orgid.value = id;
  resoninfoform.orgcode.value = code;
  resoninfoform.orgname.value = name;

}
function reloadprodgroup()
{
  if (isEmpty(resoninfoform.prodgroupcode.value)){
    resoninfoform.zmylprodgroupid.value=" ";
    resoninfoform.prodgroupcode.value="";
    resoninfoform.prodgroupname.value="";
    resoninfoform.employeetype.value="";
    resoninfoform.employeetypename.value="";
      return;
    }

    var  datahandler = new  DataHandler();
     datahandler.add_params("prodgroupcode",eval("document.resoninfoform.prodgroupcode").value) ;
    datahandler.add_params("prodgroupcode",eval("document.resoninfoform.prodgroupcode").value) ;
     datahandler.getResultFromHashMap("info" ,"zmylprodgroupid" ,"document.resoninfoform.zmylprodgroupid");
    datahandler.getResultFromHashMap("info" ,"prodgroupcode" ,"document.resoninfoform.prodgroupcode");
    datahandler.getResultFromHashMap("info" ,"prodgroupname" ,"document.resoninfoform.prodgroupname");
    datahandler.getResultFromHashMap("info" ,"employeetype" ,"document.resoninfoform.employeetype");
    datahandler.getResultFromHashMap("info" ,"employeetypename" ,"document.resoninfoform.employeetypename");
     datahandler.getResultFromHashMap("info" ,"additionalcaptionid" ,"document.resoninfoform.additionalcaptionid");
    datahandler.add_job("j_getprodgroupbycode") ;
    datahandler.runDataHandler ();
}

function poporg()
{

	var objecttype=document.resoninfoform.objecttype.value;
	var parentorgid=document.resoninfoform.parentorgid.value;

    var orgtype = 1;//resoninfoform.buyertype.value;
	if( objecttype==1 || objecttype==3){
		
		var newwin = window.open("<%=contextPath%>/zmyl/agreement/AgreementOrgSelect.jsp?<%= OvalTools.randomURL() %>&selectoption=agreementprod&zmylisseller=Y&objecttype=1&zmylagreementconfigid="+orgtype+"&languagecode=<%= strLanguageCode %>", "newwindow3", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	}
	if(objecttype==2 )
	{
 		 var newwin = window.open("<%=contextPath%>/masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>&selectoption=agreementorgprd&zmylisseller=N&zmylagreementconfigid="+orgtype+"&languagecode=<%= strLanguageCode %>", "newwindow3", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	}
   if( objecttype==4){
   var newwin = window.open("<%=contextPath%>/zmyl/agreement/AgreementOrgSelect.jsp?<%= OvalTools.randomURL() %>&selectoption=agreement&zmylisseller=Y&objecttype=1&zmylagreementconfigid="+orgtype+"&parentorgid="+parentorgid+"&languagecode=<%= strLanguageCode %>", "newwindow3", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
<!--   var newwin = window.open("<%=contextPath%>/masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>&selectoption=agreementorgprd&zmylisseller=N&zmylagreementconfigid="+orgtype+"&parentorgid="+parentorgid+"&languagecode=<%= strLanguageCode %>", "newwindow3", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");-->
  
	}
}

function page_setOrg4(id,name,code)
{
  resoninfoform.orgid.value = id;
  resoninfoform.orgcode.value = code;
  resoninfoform.orgname.value = name;

}

function popprod()
{
   var popurl = "<%=contextPath%>/masterdata/pcm/ItemSelectForPO.jsp?<%= OvalTools.randomURL() %>&selectopt=all"
   popup(popurl,'newwindow3','width=600,height=500,top=0,left=0,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes, location=no, status=yes');
}

function page_setItem(id, buyeritemcode, name, umcode, umname,prdocname,listprice,taxrate,islotcontrol, costprice,prodid,selleritemcode,attricod,piece,prdn,spec,zmycontentspec)
{
     resoninfoform.prodid.value = prodid;
     resoninfoform.prodcode.value = buyeritemcode;
        resoninfoform.prodname.value = name;
    if (popwindow != null) popwindow.close();
  //returnwarehouseandprice("","",obj[0].value,"120.00","CNY",umcode,"100");
}

function page_setProduct(id,code,name,price,spec){	
	if(switchtype==3){
		resoninfoform.serproductid.value=id;
		resoninfoform.serproductcode.value=code;
		resoninfoform.serproductname.value=name;
	}else if(switchtype==6){
		resoninfoform.prodid.value=id;
		resoninfoform.prodcode.value=code;
		resoninfoform.prodname.value=name;
	}
	hiddenFrm();
}

var isHidden;
function frm_select(e,flag){
	switchtype=flag;
	isHidden = "block";
	var productgroupid=resoninfoform.productgroupid.value;
	var _target = getPosition(e);
    var _obj = document.getElementById("summaryfrm");
    _obj.style.left = _target.x;
    _obj.style.top = _target.y + e.clientHeight;
    _obj.style.height="250px";
    _obj.style.width="530px";
    _obj.style.zIndex = 5000;
    _obj.style.display = "block";
	var strUrl = "";	
	if(flag==1 || flag==4){
		strUrl = "<%=contextPath %>/tdr/datatypein/OrgSelectPop.jsp?maxitem=8&globalpccode=1&<%= OvalTools.randomURL() %>";
	}else if(flag==2 || flag==5){
		if(flag==5)_obj.style.left = _target.x-530;
		strUrl = "<%=contextPath %>/tdr/datatypein/OrgSelectPop.jsp?maxitem=8&globalpccode=2&<%= OvalTools.randomURL() %>";
	}else if(flag==3 || flag==6){
		_obj.style.height="300px";
		strUrl = "<%=contextPath %>/tdr/datatypein/ProdSelectPop.jsp?maxitem=10&<%= OvalTools.randomURL() %>"+"&productgroupid="+productgroupid;
	}
    document.summaryfrm.location.href = strUrl;
}
function getPosition(e) {
        var left = 0;
        var top = 0;
        while (e.offsetParent) {
            left += e.offsetLeft + (e.curentStyle? (parseInt(e.curentStyle.borderLeftWidth).NaN0()):0);
            top += e.offsetTop + (e.curentStyle ? (parseInt(e.curentStyle.borderTopWidth)).NaN0() : 0);
            e = e.offsetParent;
        }
        left += e.offsetLeft + (e.curentStyle ? (parseInt(e.curentStyle.borderLeftWidth)).NaN0() : 0);
        top += e.offsetTop + (e.curentStyle ? (parseInt(e.curentStyle.borderTopWidth)).NaN0() : 0);
        return {x:left, y:top};
}

function hiddenFrm(){
	document.getElementById("summaryfrm").style.display = "none";
}



var popwindow;
function page_selectProd(){
   
	var url = "<%=contextPath%>/sfe/activity/ActivityManageProductSelect.jsp?activitymanageid="+document.resoninfoform.activitymanageid.value+"&<%= OvalTools.randomURL()%>";
	var windowAttribute = "height=400, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
  	if(popwindow!=null) popwindow.close();
  	popwindow = window.open(url,null,windowAttribute);
}

function page_setproducts(id,umcode,prodcode,prodname){
	var frm = document.resoninfoform;
	frm.prodids.value = id;
	frm.prodcode.value = prodcode;
	frm.prdn.value = prodname;
}

</script>

</head>
<body>
<table width="100%" cellspacing="0">
 <form name="resoninfoform" method="post" action="<%=contextPath%>/Dispatcher"  target="_parent">
   <input type="hidden" name="pagename" value="p_activitymanageprod">
	 <input type="hidden" name="actionname">
	 <input type="hidden" name="languagecode" value="<%= strLanguageCode %>">

<custom:hidden property="productgroupid"/>
     <custom:hidden property="parentorgid"/>
     <custom:hidden property="datacategory"/>
     <custom:hidden property="globalpccode"/>
     <custom:hidden property="objecttype"   />
     <input type="hidden" name="activitymanageid" value="<%=activitymanageid %>">
     <input type="hidden" name="na" value=" ">
     <input type="hidden" name="numrows" value="<%=visitprocessprodinfo.size()%>">

<table width="100%" cellspacing="0">
  <% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
</table>
<table width="100%" cellspacing="0" border="0" cellpadding="0">

  <tr>
      <td class="summary_top">
          <table width="100%" border="0" cellspacing="0">
      	   <%@ include file="/inc/SummarySearch.inc" %>
          </table>
      </td>
  </tr>
  <tr>
    <td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td>
				<table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellpadding="0" width="100%">
			          <tr class="deepblue-left" >
			             <td class="title_center">&nbsp;</td>
			             <td class="title_center"><%= label.getLabelName("L_ProductCode")%></td>
			             <td class="title_center"><%= label.getLabelName("L_ProductName")%></td>
			             <td class="title_center"><%= label.getLabelName("L_ Account_CustomerNumber")%></td>
			             <td class="title_center"><%= label.getLabelName("L_ develop_CustomerNumber")%></td>
			             <td class="title_center"><%= label.getLabelName("L_ Commercialsalestarget")%></td>
			             <td class="title_center"><%= label.getLabelName("L_ Netsalestarget")%></td>
			             <td class="title_center"><%= label.getLabelName("L_ Commercialpurchasetarget")%></td>
			          </tr>
					<%
						int i=0; 
						Integer idx = new Integer(-1);
                        boolean bHasChecked = false;
                        String strClassType = "";
               %>
					<logic:iterate id="reasoninfo" collection="<%=visitprocessprodinfo%>" indexId="orderid">
              
            <%
					HashMap tempMap = (HashMap)pageContext.getAttribute("reasoninfo");
					if(i%2 == 1){
						strClassType = "td-listrom";
					}else{
						strClassType = "";
					}
					i++;
					idx = new Integer(i-1);
			%>
					<tr class="<%=JspHelper.filterNull( strClassType )%>">
						<td class="td_center">
							<input type="checkbox" name="deleteids" value="<%=JspHelper.filterNull(tempMap.get("activitymanageprodid") )%>" class="checkbox">
						</td>
						<td nowrap>&nbsp;<custom:write name="reasoninfo" property="prodcode" nbsp="true" /></td>
						<td>&nbsp;<custom:write name="reasoninfo" property="prdn" nbsp="true" /></td>
						<custom:hidden name="reasoninfo" property="prodid" colIndex="<%=orderid %>"/>
						<custom:hidden name="reasoninfo" property="activitymanageprodid" colIndex="<%=orderid %>"/>
						<td><custom:text property="accountcustomernumber"   name="reasoninfo"  dataType="integer" label="L_ Account_CustomerNumber" colIndex="<%=orderid %>"/></td>
						<td><custom:text property="developcustomernumber"  dataType="integer"  name="reasoninfo"  label="L_ develop_CustomerNumber" colIndex="<%=orderid %>"/></td>
						<td><custom:text property="commercialsalestarget"   name="reasoninfo"  dataType="integer" label="L_ Commercialsalestarget" colIndex="<%=orderid %>"/></td>
						<td><custom:text property="netsalestarget"  dataType="date"  name="reasoninfo"  dataType="integer" label="L_ Netsalestarget" colIndex="<%=orderid %>"/></td>
						<td><custom:text property="commercialpurchasetarget"   name="reasoninfo"  dataType="integer" label="L_ Commercialpurchasetarget" colIndex="<%=orderid %>"/></td>
						
					</tr>
					</logic:iterate>
					<tr>
						<td>&nbsp;</td>
						<td><custom:text name="newhash" property="prodcode" size="30" readonly="true" />
							<a onclick="page_selectProd();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0" /></a>
							<custom:hidden  property="prodids" command="notnull" label="L_Product" />
						</td>
						<td><custom:text name="newhash" property="prdn" size="30" readonly="true" /></td>
						<td><custom:text property="accountcustomernumber"   name="newhash"  dataType="integer" label="L_ Account_CustomerNumber"/></td>
						<td><custom:text property="developcustomernumber"  dataType="integer"  name="newhash"  label="L_ develop_CustomerNumber"/></td>
						<td><custom:text property="commercialsalestarget"   name="newhash"  dataType="integer" label="L_ Commercialsalestarget"/></td>
						<td><custom:text property="netsalestarget"  dataType="date"  name="newhash"  dataType="integer" label="L_ Netsalestarget"/></td>
						<td><custom:text property="commercialpurchasetarget"   name="newhash"  dataType="integer" label="L_ Commercialpurchasetarget"/></td>
							<%
					 		 java.text.DateFormat format=new java.text.SimpleDateFormat("yyyy-MM-dd");
			       		
							 HashMap activitymanageinfo = (HashMap)pageContext.getAttribute("activitymanageinfo");
							 if(activitymanageinfo == null)
							  {
								 activitymanageinfo = new HashMap();
							  }
							 String readystartdate="";
							 String startdate="";
							 String enddate="";
							 readystartdate=(String)(activitymanageinfo.get("readystartdate")).toString();
							 startdate=(String)(activitymanageinfo.get("startdate")).toString();
							 enddate=(String)(activitymanageinfo.get("enddate")).toString();
							 
							 Date readystartdate1 = format.parse(readystartdate.toString());
							 Date startdate1 = format.parse(startdate.toString());
							 Date enddate1 = format.parse(enddate.toString());
							 
							 String ss=format.format(new Date());
						     Date sysdate = format.parse(ss.toString());
						    
							 if(sysdate.before(readystartdate1)){
						%>
							<custom:hidden  name="newhash" property="flag" value="0"/>
						<%} %>
						<%if(readystartdate1.before(sysdate) && readystartdate1.equals(sysdate) && sysdate.before(startdate1)){ %>
							<custom:hidden  name="newhash" property="flag" value="1"/>
						<%} %>
						<%if(startdate1.before(sysdate) && readystartdate1.equals(sysdate) && sysdate.before(enddate1) && sysdate.equals(enddate1) ){ %>
							<custom:hidden  name="newhash" property="flag" value="2"/>
						<%} %>
						<%if(sysdate.after(enddate1)){ %>
							<custom:hidden  name="newhash" property="flag" value="3"/>
						<%} %>
												
					</tr>
					<%@ include file="/inc/SummaryAction.inc"%>
				</table>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td class="summary_top"></td>
					</tr>
					<tr>
						<td colspan="3" class="title_center">
							<a onclick='page_add()'><custom:button type="2"	label="L_Add" imgsrc="add_btn.gif" border="0" style="width:60" /></a>
							<a onclick='page_save()'><custom:button type="2"	label="L_Save" imgsrc="add_btn.gif" border="0" style="width:60" /></a>
							<a onclick="page_delete()"><custom:button type="2" label="L_Delete" imgsrc="delete_btn.gif" border="0" style="width:60" /></a>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>


